/*
 * process.h
 *
 *  Created on: Mar 4, 2012
 *
 *  The process is just data. a process is initialized with a PC and occupies N memory locations, where N is the number of instructions
 *  Given a PC an a process will return an instruction.
 *
 *
 *  Needs to have some capacity to get the full Size of the program
 *
 *  Note: load full program into memory; use pc as reference, for individual instructions, access memory directly
 */

#ifndef PROCESS_H_
#define PROCESS_H_
#include "../Utility/instruction.h"

enum STATE {
	RUNNING = 0,
	RUNNABLE = 1,
	BLOCKED= 2,
};

typedef struct {
	int	process_id;
	int next_step;		// this is the step count that the CPU had gotten to when this process was
						// prempted (like a PC register value)
	enum STATE state;			// e.g. 0=running, 1=ready, 2=interrupted, 3=blocked
	int waiting_on;		// which queue is it in if it is waiting on something (blocked)
	int owns;			// which semaphore does it own
	// anything else you need
} process_control_block_struct;


typedef struct {
	int	no_steps;		// number of time steps before resetting to 0 - number of instructions
	int no_requests;	// number of requests that will be generated during the process run
	int memory_size;	// Process needs to know how much memory it an address.
	int type;			// The Type of Process 0 = Number Cruncher, 1 = Consumer, 2 = Producer
	int* address;		// If this is a consumer/producer Pair this value will be used to sync the memory, otherwise it's NULL.
	char* name;			// Name of the Process
	process_control_block_struct  pcb;

	instruction* (*getinstruction)(void *, int pc);
	int (*getpc)(void *);
	int (*savepc)(void *, int pc);
	instruction** requests;	// an array of requests, each request (e.g. io service) is issued at a specific
							// time step. These are the synchronous events that result in traps being issued.
							// You can get fancy and make this an array of RequestTypeStr which contains the
							// step number when issued, and a request type (e.g. 0=io, 1=sync, etc.)

} process;

process * process_init(int num_steps, int num_requests, int the_type, int the_id, int* the_address, int the_ram_size);

int isdone(int the_addr, int* the_arr);
void printdebug(process* p);
#endif /* PROCESS_H_ */
